<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.4"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>miniFOC: algorithm/pid.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="Acme_LOGO.png"/></td>
  <td id="projectalign">
   <div id="projectname">miniFOC<span id="projectnumber">&#160;1.0.3</span>
   </div>
   <div id="projectbrief">This open-source project aims to accomplish a FOC(Field Oriented Control) scheme that is operatable with minimum costs in China.</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.4 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_99d3723365464dd656f512988bb8dbbd.html">algorithm</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a> &#124;
<a href="#var-members">Variables</a>  </div>
  <div class="headertitle"><div class="title">pid.c File Reference</div></div>
</div><!--header-->
<div class="contents">

<p>PID algorithm implementation source code.  
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &quot;<a class="el" href="pid_8h_source.html">pid.h</a>&quot;</code><br />
<code>#include &quot;<a class="el" href="fast__math_8h_source.html">fast_math.h</a>&quot;</code><br />
<code>#include &quot;<a class="el" href="system_8h_source.html">system.h</a>&quot;</code><br />
</div>
<p><a href="pid_8c_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a58a093011af03fae7427eb1980434a5e"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="pid_8c.html#a58a093011af03fae7427eb1980434a5e">pid_config</a> (unsigned char mode)</td></tr>
<tr class="memdesc:a58a093011af03fae7427eb1980434a5e"><td class="mdescLeft">&#160;</td><td class="mdescRight">configure pid loop parameters  <a href="pid_8c.html#a58a093011af03fae7427eb1980434a5e">More...</a><br /></td></tr>
<tr class="separator:a58a093011af03fae7427eb1980434a5e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:abe6a9dce63d0eaad5a10d4c8c5ffcd07"><td class="memItemLeft" align="right" valign="top">float&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="pid_8c.html#abe6a9dce63d0eaad5a10d4c8c5ffcd07">pid_calculate_result</a> (<a class="el" href="struct_p_i_d___structure__t.html">PID_Structure_t</a> *pid_handler, float collect)</td></tr>
<tr class="memdesc:abe6a9dce63d0eaad5a10d4c8c5ffcd07"><td class="mdescLeft">&#160;</td><td class="mdescRight">calculate result using sampling value  <a href="pid_8c.html#abe6a9dce63d0eaad5a10d4c8c5ffcd07">More...</a><br /></td></tr>
<tr class="separator:abe6a9dce63d0eaad5a10d4c8c5ffcd07"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="var-members" name="var-members"></a>
Variables</h2></td></tr>
<tr class="memitem:a48934d9569b54761658f7fe0484db10c"><td class="memItemLeft" align="right" valign="top">unsigned char&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="pid_8c.html#a48934d9569b54761658f7fe0484db10c">pid_parameter_available_flag</a> = 1</td></tr>
<tr class="memdesc:a48934d9569b54761658f7fe0484db10c"><td class="mdescLeft">&#160;</td><td class="mdescRight">flag variable for PID parameter availability  <a href="pid_8c.html#a48934d9569b54761658f7fe0484db10c">More...</a><br /></td></tr>
<tr class="separator:a48934d9569b54761658f7fe0484db10c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2c7bcbec66fa40a2347b1cd253a5ae82"><td class="memItemLeft" align="right" valign="top">volatile unsigned char&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="pid_8c.html#a2c7bcbec66fa40a2347b1cd253a5ae82">pid_control_mode_flag</a> = 0</td></tr>
<tr class="memdesc:a2c7bcbec66fa40a2347b1cd253a5ae82"><td class="mdescLeft">&#160;</td><td class="mdescRight">flag variable of PID closed loop mode  <a href="pid_8c.html#a2c7bcbec66fa40a2347b1cd253a5ae82">More...</a><br /></td></tr>
<tr class="separator:a2c7bcbec66fa40a2347b1cd253a5ae82"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab051c8f4a730b934b146f330514efd95"><td class="memItemLeft" align="right" valign="top">volatile <a class="el" href="struct_p_i_d___structure__t.html">PID_Structure_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="pid_8c.html#ab051c8f4a730b934b146f330514efd95">speed_pid_handler</a></td></tr>
<tr class="memdesc:ab051c8f4a730b934b146f330514efd95"><td class="mdescLeft">&#160;</td><td class="mdescRight">algorithm handler of PID speed loop  <a href="pid_8c.html#ab051c8f4a730b934b146f330514efd95">More...</a><br /></td></tr>
<tr class="separator:ab051c8f4a730b934b146f330514efd95"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aaa8f5bad87ffc78a20f06863ab6bad5c"><td class="memItemLeft" align="right" valign="top">volatile <a class="el" href="struct_p_i_d___structure__t.html">PID_Structure_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="pid_8c.html#aaa8f5bad87ffc78a20f06863ab6bad5c">angle_pid_handler</a></td></tr>
<tr class="memdesc:aaa8f5bad87ffc78a20f06863ab6bad5c"><td class="mdescLeft">&#160;</td><td class="mdescRight">algorithm handler of PID angle loop  <a href="pid_8c.html#aaa8f5bad87ffc78a20f06863ab6bad5c">More...</a><br /></td></tr>
<tr class="separator:aaa8f5bad87ffc78a20f06863ab6bad5c"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >PID algorithm implementation source code. </p>
<dl class="section author"><dt>Author</dt><dd>Lao·Zhu </dd></dl>
<dl class="section version"><dt>Version</dt><dd>V1.0.2 </dd></dl>
<dl class="section date"><dt>Date</dt><dd>29. October 2021 </dd></dl>

<p class="definition">Definition in file <a class="el" href="pid_8c_source.html">pid.c</a>.</p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="abe6a9dce63d0eaad5a10d4c8c5ffcd07" name="abe6a9dce63d0eaad5a10d4c8c5ffcd07"></a>
<h2 class="memtitle"><span class="permalink"><a href="#abe6a9dce63d0eaad5a10d4c8c5ffcd07">&#9670;&nbsp;</a></span>pid_calculate_result()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">float pid_calculate_result </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="struct_p_i_d___structure__t.html">PID_Structure_t</a> *&#160;</td>
          <td class="paramname"><em>pid_handler</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">float&#160;</td>
          <td class="paramname"><em>collect</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>calculate result using sampling value </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">pid_handler</td><td>PID data handler </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">collect</td><td>sampled data </td></tr>
  </table>
  </dd>
</dl>
<dl class="retval"><dt>Return values</dt><dd>
  <table class="retval">
    <tr><td class="paramname">calculated</td><td>output value of PID controller </td></tr>
  </table>
  </dd>
</dl>

<p class="definition">Definition at line <a class="el" href="pid_8c_source.html#l00061">61</a> of file <a class="el" href="pid_8c_source.html">pid.c</a>.</p>

<p class="reference">References <a class="el" href="pid_8h_source.html#l00029">PID_Structure_t::expect</a>, <a class="el" href="fast__math_8h_source.html#l00020">fast_constrain</a>, <a class="el" href="pid_8h_source.html#l00027">PID_Structure_t::kd</a>, <a class="el" href="pid_8h_source.html#l00026">PID_Structure_t::ki</a>, <a class="el" href="pid_8h_source.html#l00025">PID_Structure_t::kp</a>, <a class="el" href="pid_8h_source.html#l00033">PID_Structure_t::last_error</a>, <a class="el" href="pid_8h_source.html#l00030">PID_Structure_t::maximum</a>, <a class="el" href="pid_8h_source.html#l00031">PID_Structure_t::minimum</a>, <a class="el" href="pid_8h_source.html#l00032">PID_Structure_t::sum_maximum</a>, and <a class="el" href="pid_8h_source.html#l00028">PID_Structure_t::summary</a>.</p>

<p class="reference">Referenced by <a class="el" href="gd32f1x0__it_8c_source.html#l00124">TIMER13_IRQHandler()</a>.</p>

</div>
</div>
<a id="a58a093011af03fae7427eb1980434a5e" name="a58a093011af03fae7427eb1980434a5e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a58a093011af03fae7427eb1980434a5e">&#9670;&nbsp;</a></span>pid_config()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void pid_config </td>
          <td>(</td>
          <td class="paramtype">unsigned char&#160;</td>
          <td class="paramname"><em>mode</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>configure pid loop parameters </p>

<p class="definition">Definition at line <a class="el" href="pid_8c_source.html#l00033">33</a> of file <a class="el" href="pid_8c_source.html">pid.c</a>.</p>

<p class="reference">References <a class="el" href="pid_8c_source.html#l00028">angle_pid_handler</a>, <a class="el" href="pid_8h_source.html#l00027">PID_Structure_t::kd</a>, <a class="el" href="pid_8h_source.html#l00026">PID_Structure_t::ki</a>, <a class="el" href="pid_8h_source.html#l00025">PID_Structure_t::kp</a>, <a class="el" href="pid_8h_source.html#l00030">PID_Structure_t::maximum</a>, <a class="el" href="pid_8h_source.html#l00031">PID_Structure_t::minimum</a>, <a class="el" href="pid_8c_source.html#l00020">pid_control_mode_flag</a>, <a class="el" href="pid_8c_source.html#l00024">speed_pid_handler</a>, <a class="el" href="pid_8h_source.html#l00032">PID_Structure_t::sum_maximum</a>, and <a class="el" href="system_8c_source.html#l00049">user_memset()</a>.</p>

<p class="reference">Referenced by <a class="el" href="main_8c_source.html#l00139">main()</a>, and <a class="el" href="main_8c_source.html#l00028">mdtp_callback_handler()</a>.</p>

</div>
</div>
<h2 class="groupheader">Variable Documentation</h2>
<a id="aaa8f5bad87ffc78a20f06863ab6bad5c" name="aaa8f5bad87ffc78a20f06863ab6bad5c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aaa8f5bad87ffc78a20f06863ab6bad5c">&#9670;&nbsp;</a></span>angle_pid_handler</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">volatile <a class="el" href="struct_p_i_d___structure__t.html">PID_Structure_t</a> angle_pid_handler</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>algorithm handler of PID angle loop </p>

<p class="definition">Definition at line <a class="el" href="pid_8c_source.html#l00028">28</a> of file <a class="el" href="pid_8c_source.html">pid.c</a>.</p>

<p class="reference">Referenced by <a class="el" href="flash_8c_source.html#l00046">flash_read_parameters()</a>, <a class="el" href="flash_8c_source.html#l00026">flash_write_parameters()</a>, <a class="el" href="main_8c_source.html#l00028">mdtp_callback_handler()</a>, <a class="el" href="pid_8c_source.html#l00033">pid_config()</a>, <a class="el" href="report_8c_source.html#l00015">report_local_variable()</a>, and <a class="el" href="gd32f1x0__it_8c_source.html#l00124">TIMER13_IRQHandler()</a>.</p>

</div>
</div>
<a id="a2c7bcbec66fa40a2347b1cd253a5ae82" name="a2c7bcbec66fa40a2347b1cd253a5ae82"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2c7bcbec66fa40a2347b1cd253a5ae82">&#9670;&nbsp;</a></span>pid_control_mode_flag</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">volatile unsigned char pid_control_mode_flag = 0</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>flag variable of PID closed loop mode </p>

<p class="definition">Definition at line <a class="el" href="pid_8c_source.html#l00020">20</a> of file <a class="el" href="pid_8c_source.html">pid.c</a>.</p>

<p class="reference">Referenced by <a class="el" href="main_8c_source.html#l00139">main()</a>, <a class="el" href="main_8c_source.html#l00028">mdtp_callback_handler()</a>, <a class="el" href="pid_8c_source.html#l00033">pid_config()</a>, <a class="el" href="report_8c_source.html#l00015">report_local_variable()</a>, and <a class="el" href="gd32f1x0__it_8c_source.html#l00124">TIMER13_IRQHandler()</a>.</p>

</div>
</div>
<a id="a48934d9569b54761658f7fe0484db10c" name="a48934d9569b54761658f7fe0484db10c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a48934d9569b54761658f7fe0484db10c">&#9670;&nbsp;</a></span>pid_parameter_available_flag</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned char pid_parameter_available_flag = 1</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>flag variable for PID parameter availability </p>

<p class="definition">Definition at line <a class="el" href="pid_8c_source.html#l00016">16</a> of file <a class="el" href="pid_8c_source.html">pid.c</a>.</p>

<p class="reference">Referenced by <a class="el" href="flash_8c_source.html#l00046">flash_read_parameters()</a>, <a class="el" href="flash_8c_source.html#l00026">flash_write_parameters()</a>, <a class="el" href="main_8c_source.html#l00028">mdtp_callback_handler()</a>, and <a class="el" href="report_8c_source.html#l00015">report_local_variable()</a>.</p>

</div>
</div>
<a id="ab051c8f4a730b934b146f330514efd95" name="ab051c8f4a730b934b146f330514efd95"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab051c8f4a730b934b146f330514efd95">&#9670;&nbsp;</a></span>speed_pid_handler</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">volatile <a class="el" href="struct_p_i_d___structure__t.html">PID_Structure_t</a> speed_pid_handler</td>
        </tr>
      </table>
</div><div class="memdoc">

<p>algorithm handler of PID speed loop </p>

<p class="definition">Definition at line <a class="el" href="pid_8c_source.html#l00024">24</a> of file <a class="el" href="pid_8c_source.html">pid.c</a>.</p>

<p class="reference">Referenced by <a class="el" href="flash_8c_source.html#l00046">flash_read_parameters()</a>, <a class="el" href="flash_8c_source.html#l00026">flash_write_parameters()</a>, <a class="el" href="main_8c_source.html#l00028">mdtp_callback_handler()</a>, <a class="el" href="pid_8c_source.html#l00033">pid_config()</a>, <a class="el" href="report_8c_source.html#l00015">report_local_variable()</a>, and <a class="el" href="gd32f1x0__it_8c_source.html#l00124">TIMER13_IRQHandler()</a>.</p>

</div>
</div>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.4
</small></address>
</body>
</html>
